#! /bin/bash

# Compare OS version and specified one.
# $1 ... Specified OS major version.
# $2 ... Specified OS minor version.
# return ... 1 if the same or later, 0 if older.
CheckOSVersion ()
{
	# Get OS version.
	OSVersion=$( defaults read /System/Library/CoreServices/SystemVersion ProductVersion )
	if test -z $OSVersion; then
		echo "Failed to get OS Version."
		return 0
	fi

	# Get OS Major Version.
	OSMajorVer=$( echo $OSVersion | cut -f1 -d"." )

	# Get OS Minor Version.
	OSMinorVer=$( echo $OSVersion | cut -f2 -d"." )

	# Compare the major version and specified one.
	if test $OSMajorVer -lt $1; then
		echo "OS Version must be $1.$2 or later."
		return 0
	# Compare the minor version and specified one, if the major versions are the same.
	elif test $OSMajorVer -eq $1; then
		if test $OSMinorVer -lt $2; then
			echo "OS Version must be $1.$2 or later."
			return 0
		fi
	fi

	return 1
}

# Check OS version.
if CheckOSVersion 10 4; then
	exit 97
fi

# Remove Receipt to allow down-grade installation.
rm -rf '/Library/Receipts/Steinberg MR Extension.pkg'

exit 0
